package org.example.game.biweekly.game136;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/08/03 20:45
 */
public class Solution001 {

    public static void main(String[] args) {
        System.out.println(new Solution001().winningPlayerCount(5, new int[][]{{1,1},{1,2},{1,3},{1,4}}));
    }

    public int winningPlayerCount(int n, int[][] pick) {
        int sum = 0;
        HashMap<Integer, Map<Integer, Integer>> playerGoalMap = new HashMap<>();

        for (int i = 0; i < pick.length; i++) {
            int player = pick[i][0];
            int color = pick[i][1];
            playerGoalMap.putIfAbsent(player, new HashMap<>());
            Map<Integer, Integer> colorCountMap = playerGoalMap.get(player);
            colorCountMap.putIfAbsent(color, 0);
            colorCountMap.put(color, colorCountMap.get(color) + 1);
        }

        for (int i = 0; i < n; i++) {
            if(playerGoalMap.containsKey(i)){
                Map<Integer, Integer> colorCountMap = playerGoalMap.get(i);
                for (Integer value : colorCountMap.values()) {
                    if(value > i){
                        sum++;
                        break;
                    }
                }
            }
        }

        return sum;
    }
}
